#!/usr/bin/env python3
"""Mirror GA Docker images from one Docker registry to several others.
"""

import os.path
import sys
import argparse

from lib import mirror_artifacts, re_ga, re_ea


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Mirror GA artifacts')

    parser.add_argument('--ga-version', help='GA version', required=True)
    parser.add_argument('--source-repo', help='docker registry of source image', default=mirror_artifacts.default_source_repo)
    parser.add_argument("--repos", nargs="+", default=mirror_artifacts.default_repos)

    args = parser.parse_args()
    if not re_ga.match(args.ga_version) and not re_ea.match(args.ga_version):
        sys.stderr.write(f"--ga-version must match X.Y.Z(-ea)?\n")
        sys.exit(2)

    mirror_artifacts.mirror_images(
        repos=args.repos,
        tag=args.ga_version,
        source_repo=args.source_repo)
    sys.exit(0)
